package cn.csg.iotplatform.module.system.controller.admin.publicnotice;

import cn.csg.iotplatform.framework.common.pojo.CommonResult;
import cn.csg.iotplatform.framework.common.pojo.PageResult;
import cn.csg.iotplatform.module.common.annotations.TranslateMethod;
import cn.csg.iotplatform.module.system.controller.admin.publicnotice.vo.PublicNoticeListRepVO;
import cn.csg.iotplatform.module.system.controller.admin.publicnotice.vo.PublicNoticeListReqVO;
import cn.csg.iotplatform.module.system.controller.admin.publicnotice.vo.PublicNoticeSaveReqVO;
import cn.csg.iotplatform.module.system.controller.admin.publicnotice.vo.WorkFlowVO;
import cn.csg.iotplatform.module.system.dal.dataobject.publicnotice.PublicNoticeDO;
import cn.csg.iotplatform.module.system.enums.ErrorCodeConstants;
import cn.csg.iotplatform.module.system.service.publicnotice.IPublicNoticeService;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.csg.iotplatform.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 公共通知")
@RestController
@RequestMapping("/system/public-notice")
@Validated
public class PublicNoticeController {

    @Resource
    private IPublicNoticeService publicNoticeService;

    @PostMapping("create")
    @Operation(summary = "新增")
    public CommonResult<Integer> create(@Valid @RequestBody PublicNoticeSaveReqVO saveReqVO) {
        return success(publicNoticeService.create(saveReqVO));
    }

    @PostMapping("update")
    @Operation(summary = "修改")
    public CommonResult<Integer> update(@Valid @RequestBody PublicNoticeSaveReqVO saveReqVO) {
        return success(publicNoticeService.update(saveReqVO));
    }

    @PostMapping("updateApprove")
    @Operation(summary = "审核")
    public CommonResult<Boolean> updateApprove(@Valid @RequestBody PublicNoticeDO publicNoticeDO) {
        return success(publicNoticeService.updateApprove(publicNoticeDO));
    }

/*    @PostMapping("delete")
    @Operation(summary = "删除")
    @Parameter(name = "ids", description = "id数组放body", required = true, example = "1024")
    public CommonResult<Boolean> deleteDept(@RequestBody Long[] ids) {
        publicNoticeService.delete(ids);
        return success(true);
    }*/

    @DeleteMapping("delete")
    @Operation(summary = "删除")
    @Parameter(name = "id", description = "id", required = true, example = "1024")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        publicNoticeService.delete(id);
        return success(true);
    }

    @GetMapping("/list")
    @Operation(summary = "列表")
    @TranslateMethod
    public CommonResult<PageResult<PublicNoticeListRepVO>> getList(PublicNoticeListReqVO reqVO) {
        return success(publicNoticeService.getList(reqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "查看")
    @TranslateMethod
    @Parameter(name = "id", description = "id", required = true, example = "1024")
    public CommonResult<PublicNoticeListRepVO> get(@RequestParam("id") Long id) {
        return success(publicNoticeService.get(id));
    }

/*    @PostMapping("/updateWorkFlowInfo")
    @Operation(summary = "更新流程")
    public CommonResult<Boolean> updateWorkFlowInfo(@RequestBody String bodyStr) {
        if(StrUtil.isBlank(bodyStr)) return CommonResult.error(ErrorCodeConstants.WORK_FLOW_PARAMS_EMPTY);
        return success(publicNoticeService.updateWorkFlowInfo(JSON.parseObject(bodyStr, WorkFlowVO.class)));
    }*/
}
